package com.example.restful01.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.restful01.model.Book;
import com.example.restful01.model.Register;
import com.example.restful01.service.BookService;
import com.example.restful01.service.RegisterService;
import com.example.restful01.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api") // 与前端axios的baseURL对应
@CrossOrigin // 跨域注解，也可以使用上面的全局配置
public class RegisterController {

    @Autowired
  private RegisterService registerService;

    // 书籍列表接口
    @PostMapping("/login")
    public Result sendLoginMsg(@RequestBody Register register) {

        if (registerService.isFind(register) != null){
            return Result.success("登录成功!",registerService.isFind(register));
        }
        else{
            return Result.error("登录失败!");
        }
    }
    // 添加书籍接口
    @PostMapping("/register")
    public Result sendRegisterMsg(@RequestBody Register register) {
        boolean isSuccess = registerService.save(register);
        if (isSuccess) {
            return Result.success("注册成功!");
        } else {
            return Result.error("注册失败!");
        }
    }


    // 其他接口...
}